<?php
	extract($_REQUEST);
?>

<!-- newentry.html-->

<!-- CSCI 5471 project-->

<!-- Fall 2007-->

<!-- This form allows a user to create a new post, encrypt it, and send it to the database. -->
<html>
	<head>
		<title>New Post</title>
	</head>

	<script language="Javascript" type="text/javascript" src="crypto/sha1.js"></script>
	<script language="Javascript" type="text/javascript" src="crypto/blowfish.js"></script>
	<script language="JavaScript" type="text/javascript" src="crypto/jsbn.js"></script>
	<script language="JavaScript" type="text/javascript" src="crypto/jsbn2.js"></script>
	<script language="JavaScript" type="text/javascript" src="crypto/prng4.js"></script>
	<script language="JavaScript" type="text/javascript" src="crypto/rng.js"></script>
	<script language="JavaScript" type="text/javascript" src="crypto/rsa.js"></script>
	<script language="JavaScript" type="text/javascript" src="crypto/rsa2.js"></script>
	<script language="JavaScript" type="text/javascript" src="js/storedata.js"></script>

	<body>
		<form id="adddata" method="post" action="storedata.php">
			<table border = 0>
				<tr>
					<td align="right"><b>Title:</b></td>
					<td><input type ="text" id="title" name="title" value ="" size=30 maxlength=15></td>
				</tr>

				<tr>
					<td align="right"><b>Data:</b></td>
					<td><textarea cols="80" rows="4" id="data" name="data"></textarea></td>
				</tr>

				<tr>
					<td align="right"><b>Username:</b></td>
					<td><input type ="text" name="username" id="username" value ="<?php echo $username; ?>" maxlength =50 size =30></td>
				</tr>

				<tr>
					<td align="right"><!--<b>Public Key: e:--></b></td>
					<td><input type ="hidden" id="e" value ="<?php echo $pk_e; ?>" size=30 maxlength=15></td>
				</tr>

				<tr>
					<td align="right"><!--<b>n:</b>--></td>
					<td><input type="hidden" cols="80" rows="4" name="n" id="n" value="<?php echo $pk_n; ?>">
				</tr>
				<tr>
					<td align="right"><b>Add access for users:</b></td>
					<td></td>
				</tr>
				<?php

require("./dbconnect.inc.php");

mysql_connect($host,$dbuser,$dbpassword);
@mysql_select_db($database) or die( "Unable to select database");

$datagrab=sprintf("SELECT * FROM users WHERE NOT username='%s' ORDER BY username", mysql_real_escape_string($username));

$dataresult=mysql_query($datagrab);
$numdata=mysql_numrows($dataresult);

$j=0;
while($j < $numdata){
$user=mysql_result($dataresult,$j,"username");

echo "
<tr>
	<td align=\"right\">$user</td>
	<td><input type=\"checkbox\" name=\"users[]\" value=\"$user\"></td>
</tr>";

$j++;
}

?>
				<tr>
					<td align="right">&nbsp;</td>
					<td><input type="button" value="Upload" onclick="retrievePublicKey()"></td>
				</tr>

				<!-- We need an invisible field to contain the encrypted Blowfish key. -->
				<input type="hidden" id="key" name="bfkey">

			</table>
		</form>
	</body>
</html>